<?php

namespace Yolo\Observers;

use ReflectionException;
use Yolo\Di\Annotations\Singleton;
use Yolo\Di\DI;
use Yolo\Di\Errors\CircularDependencyException;
use Yolo\Di\Errors\InvalidAttributeException;
use Yolo\Di\Errors\ParameterTypeEmptyException;

#[Singleton]
class ObserverHelper
{
    public function __construct(
        private readonly ObserverManager $observerManager
    ){
    }

    /**
     * Subscribe to an observer
     * @param string $observer
     * @return void
     * @throws ReflectionException
     * @throws CircularDependencyException
     * @throws ParameterTypeEmptyException|InvalidAttributeException
     */
    public function subscribe(string $observer): void
    {
        $this->observerManager->subscribe(DI::use($observer));
    }
}
